package Controller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;

import Entity.Message;
import Communication.Client;
import View.ConfigurationView;
import View.LoginView;
import Controller.SystemController;
import Entity.Message;


public class ConfigurationController {
	
	ConfigurationView configView;	
	Client client;
	

	/**
	 * 
	 */
	/**
	 * 
	 */
	public ConfigurationController() {
		configView = new ConfigurationView();
		configView.showWindow();
		configView.addConfigListeners(new ConfigListener());
			
			 		
		}
	
	

	/**
	 * 
	 */
	public void showWindow(){
		configView.showWindow();
	}
	
	// Hides registration window 
	/**
	 * 
	 */
	/**
	 * 
	 */
	public void hideWindow(){
		configView.hideWindow();
	}
		
		class ConfigListener implements ActionListener
		{
			LoginController loginController;
			
			@Override
			public void actionPerformed(ActionEvent event) {
				
				if (event.getSource() == configView.getOkButton())
				{
					Client client = null;
					try {
						
						client = new Client(configView.getIpField().getText(),Integer.parseInt(configView.getPortField().getText()));
						loginController = new LoginController(client);
						ArrayList<String> data = new ArrayList<String>();
						data.add(configView.getUserNameField().getText());
						data.add(configView.getDbpasswordField().getText());
						
						
						;

						
						client.sendToServer(da);
					
					
					} catch (NumberFormatException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					//hideWindow();
					//loginController.showWindow();
				}
				else if (event.getSource() == configView.getExitButton())
				{
					configView.dispose();										
				}				
			}
		}
}
